package com.eascs.bankAccount;

import com.eascs.app.dao.PageResult;
import com.eascs.app.dao.SqlPageQuery;
import com.eascs.web.sso.UserHolder;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BankAccountService {

	@Autowired
	BankAccountDao bankAccountDao;

	public boolean add(BankAccountEntity bankAccount) {
		return bankAccountDao.insert(bankAccount) > 0;
	}

	public boolean del(String id) {

		return bankAccountDao.execute("update bank_account_manage set is_del='1', updater=? where id=?", UserHolder.getUser().getCname(), id) > 0;
	}

	public PageResult<Object[]> page(int pageNo) {
		String sql = "select id, account_no, bank_account_name, bank_card_no, open_account_bank, remarks from bank_account_manage where 1=1 and is_del=0 ";

		SqlPageQuery<Object[]> sqlPageQuery = new SqlPageQuery<>(Object[].class, 10, pageNo);
		sqlPageQuery.setQuerySql(sql);

		return bankAccountDao.findDataWithPage(sqlPageQuery);
	}

	public List<String> getBankAccount() {
		String sql = "select bank_card_no from bank_account_manage where is_del=0 ";
		return bankAccountDao.findSimpleObjectList(sql, String.class);
	}
}
